from config import *
import fbs
import xmb


class GYS:
    def __init__(self, name, warehouse, price_in, price_out):
        self.name = name
        self.warehouse = warehouse  # 供应商的仓库名字
        self.price_in = price_in  # 供应商入库单价
        self.price_out = price_out  # 供应商出库单价

        self.supplier_form = ''  # 供货申请单
        self.gys_buy_form = ''  # 供应商入库单 增加库存
        self.put_out_form = ''  # 出库单号

        # self.supplier_form = 'GHSQ-20240502-8197'  # 供货申请单
        # self.gys_buy_form = 'RK-20240502-8198'  # 供应商入库单 增加库存
        # self.put_out_form = 'CK-20240502-8184'  # 出库单号




    # 切换角色
    def into(self):
        sleep(1)
        xpath("//span[contains(text(), '好')]")  # 点击 右上角的 “上午好或下午好”
        xpath("//li[contains(text(), '切换账号')]"),sleep(0.3)  # 点击 切换账号
        xpath("//div[contains(text(), '%s')]" % self.name)  # 点击 名字 进行切换 账号
        sleep(2)

    def add_supplier_form(self, xmb):
        # 新增供货申请单
        sleep(2)
        query('//*[@id="app"]/div/section/section/main/section/div/*/form/*', "新增物资申请单")
        # 供货申请单新增加出库对象
        xpath(
            '/html/body/div[1]/div/section/section/main/section/div/div[4]/div[1]/div[2]/div/div/form/div/div[1]/div/div/div/div/input')
        query('/html/body/div[6]/div[1]/div[1]/ul/*', "项目部")

        # 项目标段
        xpath(
            '//*[@id="app"]/div/section/section/main/section/div/div[4]/div/div[2]/div/div/form/div/div[3]/div/div/div/div/input')
        # 标段位置
        sleep(0.5)
        query('/html/body/*/*/*/ul/li', project_section)
        xpath(
            '//*[@id="app"]/div/section/section/main/section/div/div[4]/div/div[2]/div/div/form/div/div[4]/div/div/div/div/input')
        query('//ul/*', xmb.purchase_form)  # 关联采购单
        xpath_input(
            '//*[@id="app"]/div/section/section/main/section/div/div[4]/div/div[2]/div/div/form/div/div[7]/div/div/div/textarea',
            '备注')
        # 供货数量
        xpath_input(
            '//*[@id="app"]/div/section/section/main/section/div/div[4]/div/div[2]/div/div/div/div/div[3]/table/tbody/tr/td[8]/div/div/input',
            count)
        query('//*[@id="app"]/div/section/section/main/section/div/*/div/*/div/*', "申请供货")
        # 保存供货申请单
        self.supplier_form = xpath_text(
            '//*[@id="app"]/div/section/section/main/section/div/div[2]/div[1]/div/div[3]/table/tbody/tr[1]/td[2]/div')
        print('供货申请单：' + self.supplier_form)
        sleep(1)

    # 供应商进行补货
    def put_in(self):
        sleep(1)
        xpath('//*[@id="app"]/div/section/section/main/section/div/*/ul/*/div[contains(text(), "出入库管理")]')
        query("//label[2]", "入库")
        query('//*[@id="app"]/div/section/section/main/section/div/*/*/div/*/div/*/div/*', "新增入库单")
        xpath(
            '//*[@id="app"]/div/section/section/main/section/div/div[6]/div[3]/div/div[2]/div/div[1]/div[1]/div[3]/div[2]/div/div/input')
        driver.find_element_by_xpath('/html/body/*/*/*/ul/*/span[contains(text(), "%s")]' % self.warehouse).click()
        xpath_input(
            '//*[@id="app"]/div/section/section/main/section/div/div[6]/div[3]/div/div[2]/div/div[1]/div[1]/div[7]/div[2]/div/input',
            "炸薯条")
        xpath_input(
            '//*[@id="app"]/div/section/section/main/section/div/div[6]/div[3]/div/div[2]/div/div[1]/div[1]/div[9]/div[2]/div/textarea',
            "供应商入货")
        # # 增加物料信息
        sleep(1)
        material_message(material_name, count,
                         '//*[@id="app"]/div/section/section/main/section/div/div[6]/div[3]/div/div[2]/div/div[1]/div[2]/div/div[3]/table/tbody/tr/td[2]/div/div/input',
                         '//*[@id="app"]/div/section/section/main/section/div/div[6]/div[4]/div/div[2]/div/div[1]/form/div[2]/div/div/input',
                         '//*[@id="app"]/div/section/section/main/section/div/div[6]/div[4]/div/div[2]/div/*/form/button',
                         '//*[@id="app"]/div/section/section/main/section/div/div[6]/div[4]/div/div[2]/div/div[2]/div/*/table/tbody/*/*/div/button/',
                         '//*[@id="app"]/div/section/section/main/section/div/div[6]/div[3]/div/div[2]/div/div[1]/div[2]/div/div[3]/table/tbody/tr/td[7]/div/div/input')
        # 供应商入货单价
        xpath_input(
            "/html/body/div[1]/div/section/section/main/section/div/div[6]/div[3]/div/div[2]/div/div[1]/div[2]/div/div[3]/table/tbody/tr/td[6]/div/div/input",
            self.price_in)
        # 确认入库
        query('//*[@id="app"]/div/section/section/main/section/div/div[6]/div[3]/div/*/div/*/', "确认提交")
        # 保存供应商入库单号
        self.gys_buy_form = xpath_text(
            "/html/body/div[1]/div/section/section/main/section/div/div[6]/div[1]/div/div[2]/div/div[3]/div/div[3]/table/tbody/tr[1]/td[2]/div")
        print("供应商入库单：" + self.gys_buy_form)
        sleep(0.5)
        # 进行入库
        xpath(
            '//*[@id="app"]/div/section/section/main/section/div/div[6]/div[1]/div/div[2]/div/div[3]/div/div[3]/table/tbody/tr[1]/td[10]/div/button[4]/span')
        query('//*[@id="app"]/div/section/section/main/section/div/div[6]/div[3]/div/*/div/*', "入库")

    def put_out(self):
        sleep(3)  # 因为经常在这里有问题 提示找不到左上角出库元素 所以 要强制等待 +
        # xpath('//*[@id="app"]/div/section/section/main/section/div/*/ul/*/div[contains(text(), "出入库管理")]')
        query("//label[1]", "出库")
        query('//*[@id="app"]/div/section/section/main/section/div/*/*/*/*/*/*/*/*', "新增出库单")
        # # 出库对象 单据信息
        xpath(
            '//*[@id="app"]/div/section/section/main/section/div/div[6]/div[2]/div/div[2]/div/div[1]/div[2]/div[2]/div/div/input')
        query('//ul/*', "项目部")
        # 查询 供货申请单
        xpath(
            '//*[@id="app"]/div/section/section/main/section/div/div[6]/div[2]/div/div[2]/div/div[1]/div[3]/div[2]/div/div[1]/input')
        query('//ul/*', self.supplier_form)
        # 查询出库仓库
        xpath(
            '/html/body/div[1]/div/section/section/main/section/div/div[6]/div[2]/div/div[2]/div/div[1]/div[5]/div[2]/div/div/input')
        query('/html/body/*/*/*/ul/*', self.warehouse)
        # query('//ul/*', self.warehouse)
        # 输入其他信息
        xpath_input(
            '//*[@id="app"]/div/section/section/main/section/div/div[6]/div[2]/div/div[2]/div/div[1]/div[9]/div[2]/div/input',
            location)
        xpath_input(
            '//*[@id="app"]/div/section/section/main/section/div/div[6]/div[2]/div/div[2]/div/div[1]/div[10]/div[2]/div/textarea',
            "备注")
        driver.find_element_by_xpath(
            '//*[@id="app"]/div/section/section/main/section/div/div[6]/div[2]/div/div[2]/div/div[2]/div/div[3]/table/tbody/tr/td[8]/div/div/input').clear()  # 清空信息
        xpath_input(
            '//*[@id="app"]/div/section/section/main/section/div/div[6]/div[2]/div/div[2]/div/div[2]/div/div[3]/table/tbody/tr/td[8]/div/div/input',
            self.price_out)  # 出库单价
        xpath_input(
            '//*[@id="app"]/div/section/section/main/section/div/div[6]/div[2]/div/div[2]/div/div[2]/div/div[3]/table/tbody/tr/td[9]/div/div/input',
            count)  # 出库数量
        sleep(0.5)
        query('//*[@id="app"]/div/section/section/main/section/div/*/*/*/*/*/*', "确定出库")
        # 保存单单据
        self.put_out_form = xpath_text(
            '//*[@id="app"]/div/section/section/main/section/div/div[6]/div[1]/div[1]/div[2]/div/div[3]/div/div[3]/table/tbody/tr[1]/td[2]/div')
        print("供应商出库单：" + self.put_out_form)
        # 出库完 右上角的X
        sleep(2)
        xpath('//*[@id="app"]/div/section/section/main/section/div/div[6]/div[1]/div[1]/div[1]/button/i')
        sleep(1)
